<template>
	<view class="">
		<view class="contractbox" v-for="(item,index) in arr" :key="index">
			<view class="contract">
				{{item.name}}
			</view>
			<view class="lookfind" @click="lookfind(item.myfile)">
				下载
			</view>
		</view>
	</view>



</template>

<script>
	import {
		getfilelist
	} from "../../api/api/index"
	export default {
		data() {
			return {
				arr: []
			}
		},
		onLoad() {
			getfilelist().then(res => {
				// console.log(res.data)
				this.arr = res.data
			})
		},
		methods: {
			lookfind(v) {
				if (v.indexOf(".png") != -1 || v.indexOf(".jpg") != -1 || v.indexOf(".gif") != -1 || v.indexOf(".jpeg") !=
					-1 || v.indexOf(".tiff") != -1 || v.indexOf(".bmp") != -1) {
					let arrs = [v]
					uni.previewImage({
						urls: arrs,
						current: arrs[0]
					})
				} else {
					uni.downloadFile({
						url: v, //下载地址接口返回
						success: function(res) {
							var filePath = res.tempFilePath;
							uni.saveFile({
								tempFilePath: filePath,
								success: function(res) {
									var savedFilePath = res.savedFilePath;
									uni.openDocument({
										filePath: savedFilePath,
										success: function(res) {
										},
										fail: (err) => {
											console.log(err)
										}
									});

								}
							});
						},
						fail: (err) => {
							uni.showToast({
								icon: 'none',
								mask: true,
								title: '失败请重新下载',
							});
						},
					});
				}


			},

		}
	}
</script>

<style scoped lang="less">
	.contractbox {
		display: flex;
		justify-content: space-between;
		padding: 63rpx 31rpx;
		box-sizing: border-box;
		width: 709rpx;
		height: 160rpx;
		background-color: #ffffff;
		box-shadow: 3rpx 4rpx 7rpx 0rpx rgba(180, 180, 180, 0.2);
		border-radius: 10rpx;
		margin-left: 20rpx;
		margin-top: 29rpx;
		margin-top: 11rpx;

		.contract {
			font-family: MicrosoftYaHei-Bold;
			font-size: 30rpx;
			color: #000000;
		}

		.lookfind {
			font-family: MicrosoftYaHei;
			font-size: 26rpx;
			color: #f69a0a;
		}
	}
</style>
